import GlobalConfig from '../base-options'
import XEUtils from 'xe-utils'

/**
 * 全局参数设置
 */
function setup (options) {
  return XEUtils.merge(GlobalConfig, options)
}

const installedPlugins = []
function use (Plugin, options) {
  if (Plugin && Plugin.install) {
    if (installedPlugins.indexOf(Plugin) === -1) {
      Plugin.install(VCUCharts, options)
      installedPlugins.push(Plugin)
    }
  }
  return VCUCharts
}

export const VCUCharts = {
  use,
  setup,
}

/**
 * 获取所有导出类型
 */
 Object.defineProperty(VCUCharts, 'exportTypes', {
  get () {
    return Object.keys(VCUCharts.types)
  }
})

/**
 * 获取所有导入类型
 */
Object.defineProperty(VCUCharts, 'importTypes', {
  get () {
    const rest = []
    XEUtils.each(VCUCharts.types, (flag, type) => {
      if (flag) {
        rest.push(type)
      }
    })
    return rest
  }
})

export default VCUCharts